home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: hex to dec function?
- Date: 21 Feb 96 13:34:09 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.824909649@rscernix>
- References: <4gdh1b$bg@mailhost.mwmicro.com> <4gdolr$ha9@madeline.INS.CWRU.Edu>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <4gdolr$ha9@madeline.INS.CWRU.Edu> mab22@po.CWRU.Edu (Michael A. Balfour) writes:
-
-
- >In a previous article, aschlies@citynet.net () says:
- >
- >>Hi There,
- >>
- >>Is there a function that converts HEX to Dec in ANSI C?
- >>
- >You could try sscanf. For example:
- >
- >main()
- >{
- > char hex[9];
- > int dec;
- >
- > strcpy(hex,"FFFF");
- > sscanf(hex,"%xd",&dec);
- ^
- What's the purpose of this 'd'?
-
- It's advisable to pass a pointer to unsigned int when using %x in scanf.
- Otherwise you violate a "shall" in the standard, invoking undefined
- behaviour.
-
- >}
-
- BTW, strtol will work for any base in the 2..36 range.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-